home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSDESC.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  10.3 KB  |  245 lines

  1. rem 
  2. rem $Header: dbmsdesc.sql 7020100.1 94/09/23 22:14:21 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      dbmsdesc.sql - describe stored procedures and functions
  7. Rem    DESCRIPTION
  8. Rem      Given a stored procedure, return a description of the 
  9. Rem      arguments required to call that procedure.
  10. Rem    RETURNS
  11. Rem 
  12. Rem    NOTES
  13. Rem      The procedural option is needed to use this facility.
  14. Rem      
  15. Rem    MODIFIED   (MM/DD/YY)
  16. Rem     adowning   03/29/94 -  merge changes from branch 1.6.710.1
  17. Rem     adowning   02/02/94 -  split file into public / private binary files
  18. Rem     rkooi      11/26/92 -  change some comment 
  19. Rem     rkooi      11/21/92 -  check for top level functions 
  20. Rem     rkooi      11/17/92 -  get rid of database name 
  21. Rem     rkooi      11/12/92 -  change name res stuff 
  22. Rem     mmoore     11/01/92 -  Creation 
  23.  
  24. REM ********************************************************************
  25. REM THIS PACKAGE MUST NOT BE MODIFIED BY THE CUSTOMER.  DOING SO
  26. REM COULD CAUSE INTERNAL ERRORS AND SECURITY VIOLATIONS IN THE
  27. REM RDBMS.  SPECIFICALLY, THE PSD* ROUTINES MUST NOT BE CALLED
  28. REM DIRECTLY BY ANY CLIENT AND MUST REMAIN PRIVATE TO THE PACKAGE BODY.
  29. REM ********************************************************************
  30. create or replace package dbms_describe is
  31.  
  32.   ------------
  33.   --  OVERVIEW
  34.   --
  35.   -- This package is used to describe the arguments of a stored 
  36.   -- procedure.  The client specifies an object name and describe returns 
  37.   -- a set of indexed tables with the results.  Full name 
  38.   -- translation is performed and security checking is also
  39.   -- checked on the final object.
  40.  
  41.   --------
  42.   --  USES
  43.   --
  44.   -- The primary client of this package is ODESSP (Oracle Call 
  45.   -- Interface Describe PRocedure).
  46.  
  47.   ---------------
  48.   --  LIMITATIONS
  49.   --
  50.   --  Currently describes of remote objects are not supported.  It is
  51.   --  intended to support this at some point in the future.
  52.   -- 
  53.   --  Currently descibes of all procedures/functions within a package
  54.   --  is not supported. We could add a 'describe_package' procedure
  55.   --  that returns the names of all procedures/functions for the named
  56.   --  package and then the client could call 'describe_procedure' for
  57.   --  those in which it has an interest.
  58.  
  59.   ------------
  60.   --  SECURITY
  61.   --
  62.   -- Describe is available to PUBLIC and performs it's own
  63.   -- security checking based on the object being described.
  64.  
  65.   -----------------------
  66.   --  TYPES AND CONSTANTS
  67.   --
  68.   type varchar2_table is table of varchar2(30) index by binary_integer;
  69.   -- Indexed table type which is used to return the argument names.
  70.  
  71.   type number_table   is table of number       index by binary_integer;
  72.   -- Indexed table type which is used to return various argument fields.
  73.  
  74.   ------------
  75.   --  EXAMPLES
  76.   --
  77.   --  External service interface
  78.   ------------------------------
  79.   --
  80.   -- The ODESSP OCI call may be used to call this routine from a user 
  81.   -- program.  (See the Oracle Call Interface guide for a description)  
  82.   -- Also, this routine could be called from other stored procedures 
  83.   -- using the varchar2_table and number_table types.
  84.   --
  85.   --   EXAMPLE :
  86.   --
  87.   --   Client provides -
  88.   --
  89.   --   object_name - SCOTT.ACCOUNTING.ACCOUNT_UPDATE
  90.   --   total_elements - 100
  91.   --   
  92.   --   ACCOUNT_UPDATE is an overloaded function in package ACCOUNTING
  93.   --   with specification :
  94.   --
  95.   --     type number_table is table of number index by binary_integer
  96.   --     table account (account_no number, person_id number,
  97.   --                    balance number(7,2))
  98.   --     table person  (person_id number(4), person_nm varchar2(10))
  99.   --
  100.   --     function ACCOUNT_UPDATE (account number, 
  101.   --       person person%rowtype, amounts number_table,
  102.   --       trans_date date) return account.balance%type;
  103.   --
  104.   --     function ACCOUNT_UPDATE (account number, 
  105.   --       person person%rowtype, amounts number_table,
  106.   --       trans_no number) return account.balance%type;
  107.   --
  108.   --
  109.   --   Values returned -
  110.   --
  111.   --   overload position   argument  level  datatype length prec scale rad
  112.   --   -------------------------------------------------------------------
  113.   --          1        0                0   NUMBER      7    2     0    0
  114.   --          1        1   ACCOUNT      0   NUMBER     22    0     0    0
  115.   --          1        2   PERSON       0   RECORD
  116.   --          1        2     PERSON_ID  1   NUMBER      4    0     0    0
  117.   --          1        2     PERSON_NM  1   VARCHAR2   10
  118.   --          1        3   AMOUNTS      0   TABLE
  119.   --          1        3                1   NUMBER     22    0     0    0
  120.   --          1        4   TRANS_NO     0   NUMBER     22    0     0    0
  121.   --
  122.   --          0        0                0   NUMBER      7    2     0    0
  123.   --          0        1   ACCOUNT      0   NUMBER     22    0     0    0
  124.   --          0        2   PERSON       0   RECORD
  125.   --          0        2    PERSON_ID   1   NUMBER      4    0     0    0
  126.   --          0        2    PERSON_NM   1   VARCHAR2   10
  127.   --          0        3   AMOUNTS      0   TABLE
  128.   --          0        3                1   NUMBER     22    0     0    0
  129.   --          0        4   TRANS_DATE   0   DATE
  130.   --
  131.  
  132.   ----------------------------
  133.   --  PROCEDURES AND FUNCTIONS
  134.   --
  135.   procedure describe_procedure (object_name in varchar2,
  136.     reserved1 in varchar2, reserved2 in varchar2,
  137.     overload out number_table, position out number_table,
  138.     level out number_table, argument_name out varchar2_table,
  139.     datatype out number_table, default_value out number_table,
  140.     in_out out number_table, length out number_table,
  141.     precision out number_table, scale out number_table,
  142.     radix out number_table, spare out number_table);
  143.   --  
  144.   --  Describe pl/sql object with the given name.  Returns the arguments
  145.   --    ordered by overload, position.  The name resolution follows the
  146.   --    rules for SQL.  Top level procedures and functions, as well as
  147.   --    packaged procedures and functions, may be described.  Procedures
  148.   --    and functions in package STANDARD must be prefixed by "STANDARD"
  149.   --    (e.g., 'standard.greatest' will describe function "GREATEST" in
  150.   --    package "STANDARD").
  151.   --  Input parameters:
  152.   --    object_name 
  153.   --      The name of the procedure being described. The form is
  154.   --        [[part1.]part2.]part3[@dblink]
  155.   --      The syntax follows the rules for identifiers in SQL.  The name may
  156.   --      be a synonym and may contain delimited identifiers (double quoted
  157.   --      strings). This parameter is required and may not be null.
  158.   --      The total length of the name is limited to 197 bytes.
  159.   --    reserved1, reserved2
  160.   --      Reserved for future use.  Must be set to null or empty string.
  161.   --  Output parameters:
  162.   --    overload
  163.   --       A unique number assigned to the procedure signature.  If a 
  164.   --       procedure is overloaded, this field will hold a different
  165.   --       value for each version of the procedure.
  166.   --    position
  167.   --       Position of the argument in the parameter list beginning with 1.
  168.   --       Position 0 indicates a function return value.
  169.   --    level
  170.   --       If the argument is a composite type (like record), this
  171.   --       parameter returns the level of datatype.  See example
  172.   --       section for a usage example.
  173.   --    argument_name
  174.   --       The name of the argument.
  175.   --    datatype
  176.   --       Oracle datatype of the parameter. These are:
  177.   --           0 - This row is a placeholder for a procedure with
  178.   --               no arguments.
  179.   --           1 - VARCHAR2
  180.   --           2 - NUMBER
  181.   --           3 - NATIVE INTEGER (for PL/SQL's BINARY_INTEGER)
  182.   --           8 - LONG
  183.   --          11 - ROWID
  184.   --          12 - DATE
  185.   --          23 - RAW
  186.   --          24 - LONG RAW
  187.   --          96 - CHAR (ANSI FIXED CHAR)
  188.   --         106 - MLSLABEL
  189.   --         250 - PL/SQL RECORD (see "Notes:" below)
  190.   --         251 - PL/SQL TABLE
  191.   --         252 - PL/SQL BOOLEAN (see "Notes:" below)
  192.   --    default_value
  193.   --       1 if the parameter has a default value.  0, otherwise.
  194.   --    in_out
  195.   --       0 = IN param, 1 = OUT param, 2 = IN/OUT param
  196.   --    length
  197.   --       The data length of the argument.  For string types, length is
  198.   --       the "N" in CHAR/VARCHAR2(N);  N is today bytes ON THE SERVER
  199.   --       SIDE (for multi-byte it may differ on the client side) and 
  200.   --       may someday be the number of characters rather than bytes.
  201.   --    precision
  202.   --       Precision of the argument (if the datatype is number).
  203.   --    scale
  204.   --       Scale of the argument (if the datatype is number).
  205.   --    radix
  206.   --       Radix of the argument (if the datatype is number).
  207.   --    spare
  208.   --       Reserved for future functionality.
  209.   --  Exceptions:
  210.   --    ORA-20000 - A package was specified.  Can only specify top-level
  211.   --      procedure/functions or procedures/functions within a package.
  212.   --    ORA-20001 - The procedure/function does not exist within the package.
  213.   --    ORA-20002 - The object is remote.  This procedure cannot currently 
  214.   --      describe remote objects.
  215.   --    ORA-20003 - The object is invalid.  Invalid objects cannot be
  216.   --      described.
  217.   --    ORA-20004 - A syntax error in the specification of the object's name.
  218.   --  Notes:
  219.   --    There is currently no way from a 3gl to directly bind to an
  220.   --    argument of type 'record' or 'boolean'.  For booleans, there are
  221.   --    the following work-arounds.  Assume function F returns a boolean, G
  222.   --    is a procedure with one IN boolean argument, and H is a procedure
  223.   --    which has one OUT boolean argument. 
  224.   --    Then you can execute these functions, binding in DTYINTs (native
  225.   --    integer) as follows, where 0=>FALSE and 1=>TRUE:
  226.   --
  227.   --      begin :dtyint_bind_var := to_number(f); end;
  228.   --
  229.   --      begin g(to_boolean(:dtyint_bind_var)); end;
  230.   -- 
  231.   --      declare b boolean; begin h(b); if b then :dtyint_bind_var := 1;
  232.   --        else :dtyint_bind_var := 0; end if; end;
  233.   --
  234.   --    Access to procedures with arguments of type 'record' would require 
  235.   --    writting a wrapper similar to that in the 3rd example above (see
  236.   --    funciton H).
  237. end;
  238. /
  239. drop public synonym dbms_describe
  240. /
  241. create public synonym dbms_describe for sys.dbms_describe
  242. /
  243. grant execute on dbms_describe to public
  244. /
  245.